#include "plwordnetdao.h"

#include <QSqlQuery>
#include <QSqlError>

#include <QDebug>

PlWordNetDAO::PlWordNetDAO()
{
    db = QSqlDatabase::addDatabase("QMYSQL");
    db.setHostName("localhost");
    db.setDatabaseName("plwordnet_20");
    db.setUserName("root");
    db.setPassword("password");
    if (!db.open())
        qCritical("Database Error: ", qPrintable(db.lastError().text()));
}

QStringList PlWordNetDAO::findSynsets(const QString &lemma) const
{
    QStringList synsets;
    QSqlQuery synsetQuery(QString("select syn_id from plwordnet_20.unitandsynset join plwordnet_20.lexicalunit "
                              "on lex_id = id "
                              "where lemma = \"%1\";"
                     ).arg(lemma));
    synsetQuery.setForwardOnly(true);
    while(synsetQuery.next())
        synsets << synsetQuery.value(0).toString();
    return synsets;
}
